<?php

namespace app\api\model;

use app\admin\model\ServersUser;
use app\admin\model\SystemConfig;
use think\facade\Db;
use think\Model;
use think\model\concern\SoftDelete;

/**
 * 商品列表
 */
class Order extends Model
{

    // 开启自动写入时间戳字段
    protected $auto_timestamp = 'false';
    // 设置json类型字段
	// protected $json = ['sf'];
 
   // protected $append = ['boot', 'is_after'];
      // 追加属性 
      use SoftDelete;

      protected $deleteTime = 'delete_time';
  
      public function getPayTimeAttr($value) {
         if ($value) {
             return date('Y-m-d H:i:s', $value);
         } else {
             return '';
         }         
      }

     //订单时间超出45天自动删除
     public function complete_theservice(){
        Db::name('order')
        ->where("delete_time",Null)
        ->field("id,status,order_no,expiration_deletion_time,uid,delete_time")
        ->chunk(100, function($users) {
            foreach ($users as $user) {
                //处理逻辑修改状态
                if($user["expiration_deletion_time"] < time()){
                    Db::name("order")->where("id",$user["id"])->update(["delete_time"=>time()]);
                }
               
            }
        });
        return ["code"=>1];
     }
     
   
}
